package stream.middleFunction;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Function;
import java.util.stream.Stream;


public class Demo1 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "a", "ab", "abdd", "ccc", "bc","a","ccc");
        //filte 过滤器
        list.stream().filter(s->s.startsWith("a")).filter(s->s.length() == 2).forEach(s-> System.out.println(s));
        //limit只获取前几个元素
        list.stream().limit(2).forEach(s-> System.out.println(s));
        //skip 跳过前几个元素
        list.stream().skip(2).forEach(s-> System.out.println(s));
        //去重
        list.stream().distinct().forEach(s->System.out.println(s));
        //合并流
        ArrayList<String> list2 = new ArrayList<>();
        list2.add("A-1");
        list2.add("B-2");
        Stream.concat(list.stream(),list2.stream()).forEach(s-> System.out.println(s));
        System.out.println("---------------------------------------");
        //转换数据类型
        /*list2.stream().map(new Function<String, Integer>() {

            @Override
            public Integer apply(String s) {
                //这里将字符串转换成整数
                String[] arr = s.split("-");
                return Integer.parseInt(arr[1]);
            }
        }).forEach(s-> System.out.println(s));*/
        list2.stream().map(s->s.split("-")[1]).forEach(s-> System.out.println(s));



    }
}
